<!DOCTYPE html>
<html>
<head>
    {include file="public/head"}
    <style>
        .weui-uploader__input{position: absolute;left: 0;opacity: 0;width: 100%;height: 100%;}
    </style>
</head>
<body>
<div class="g-flexview">
    <header class="m-navbar">
        <a href="javascript:history.back();" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">个人资料</span></div>
    </header>
    <div class="g-scrollview">
        <div class="m-cell">
            <a class="cell-item" href="#">
                <div class="cell-left">头像</div>
                <div class="cell-right cell-arrow" style="height: 50px;">
                    <img src="{$user['avatar']}" alt="头像" height="90%" id="avatar">
                    <input class="weui-uploader__input" accept="image/*" type="file" onchange="previewImage(this)">
                </div>
            </a>
            <a class="cell-item" href="/index/set/nickname.html">
                <div class="cell-left">昵称</div>
                <div class="cell-right cell-arrow">{$user['nickname']}</div>
            </a>
            <a class="cell-item" href="/index/user/real">
                <div class="cell-left">实名认证</div>
                <div class="cell-right cell-arrow">
                    {if condition="$user['is_real'] == 0"}完善实名{else/}已实名{/if}
                </div>
            </a>
            <a class="cell-item" href="/index/set/loginPassword.html">
                <div class="cell-left">登录密码</div>
                <div class="cell-right cell-arrow"></div>
            </a>
            <a class="cell-item" href="/index/set/tradePassword.html">
                <div class="cell-left">交易密码</div>
                <div class="cell-right cell-arrow"></div>
            </a>
            <a class="cell-item version" href="javascript:;">
                <div class="cell-left">版本</div>
                <div class="cell-right cell-arrow"></div>
            </a>
        </div>
        <div class="m-button">
            <a class="btn-block btn-danger" href="/index/login/logout">退出当前账号</a>
        </div>
    </div>
</div>
{include file="public/js"}
<script>
    !function ($) {
        $('.version').click(function () {
            dialog.alert('V1.0.0');
        });
    }(jQuery);

    // 图片上传
    function previewImage(file) {
        var MAXWIDTH = 1000;
        var MAXHEIGHT = 1200;
        if (file.files && file.files[0]) {
            var reader = new FileReader();
            if (file.files[0].size / 1024 > MAXWIDTH) {
                dialog.alert('图片尺寸过大');return '';
            }
            reader.onload = function (evt) {
                $.post("/index/set/uploadAvatar",{imgbase64: evt.target.result},function(rs){
                    $('#avatar').attr('src',evt.target.result);
                    //$(file).parent().prev().html('<li  onclick="removeimg(this)" class="weui-uploader__file" style="background-image:url('+evt.target.result+')"><input value="'+rs.src+'"  type="hidden"  name="files" /></li>');
                },'json');
            };
            reader.readAsDataURL(file.files[0]);
            console.log(file.files[0]);
        }
    }
</script>
</body>
</html>